package com.productinfo.mapper;

import com.productinfo.entity.Productinfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author guanfenga@yonyou.com
 * @since 2023-02-10
 */
public interface ProductinfoMapper extends BaseMapper<Productinfo> {

    String ProductInfoObj = "`productId`, `productTypeId`, `shopInfoId`, `brandId`, `productName`, `productFullName`, `openPrice`,\n" +
            "`marketPrice`, `salesPrice`, `costPrice`, `memberPrice`, `stockUpDate`, `weight`, `weightUnit`, `specification`,\n" +
            "`describle`, `logoImg`, `createDate`, `updateDate`, `putSaleDate`, `isPutSale`, `isShow`, `productCode`,\n" +
            "`functionDesc`, `storeNumber`, `isChargeFreight`, `freightPrice`, `productAttributeValue`, `productAttribute`,\n" +
            "`productParametersValue`, `goods`, `productRemark`, `isPass`, `note`, `productTag`, `seoTitle`, `seoKeyWord`,\n" +
            "`seoDescription`, `totalHits`, `totalSales`, `isRecommend`, `isNew`, `isHot`, `isTop`, `giveAwayCoinNumber`,\n" +
            "`barCode`, `qrCode`, `sku`, `measuringUnitName`, `packingSpecifications`, `manufacturerModel`, `category_level1`,\n" +
            "`category_level2`, `category_level3`, `category_level4`, `deliveryAddressProvince`, `deliveryAddressCities`, `shopcompany`,\n" +
            "`fromid`, `fproductId`, `fsalesPrice`, `areaPrice`, `otherReason`, `reason`, `greenFlag`, `frombrand`, `shopfromid`, `deliveryArea`,\n" +
            "`services`, `connotbuy`, `cpId`, `CERT_CODE`, `CERT_EXPIR`, `BRAND_ZH_NAME`, `DIR_CODE`, `MANUF_NAME` ";

    /**
     * 查询所有商品
     * @return
     */
    @Select("SELECT "+ProductInfoObj+" FROM mall_productinfo ")
    List<Productinfo> queryProductInfoAll();

    /**
     * 根据主键查询商品
     * @param productId
     * @return
     */
    @Select("SELECT "+ProductInfoObj+" FROM mall_productinfo p where p.productId = #{productId}")
    Productinfo queryProductInfoById(@Param("productId") String productId);

    /**
     * 根据分类ID 查询相关商品信息
     * @param productId
     * @return
     */
//    @Select("SELECT "+ProductInfoObj+"FROM mall_productinfo p where p.productTypeId = #{producttypeId} order by p.salesPrice asc  LIMIT 5")
    @Select("SELECT "+ProductInfoObj+" FROM\n" +
            "\tmall_productinfo p \n" +
            "WHERE\n" +
            "\tp.productTypeId IN ( SELECT p1.productTypeId FROM mall_productinfo p1 WHERE p1.productId = #{productId} ) \n" +
            "ORDER BY\n" +
            "\tRAND() \n" +
            "\tLIMIT  3")
    List<Productinfo> queryRelevantCommodity(@Param("productId") String productId);
}
